package com.test.practice.io.charstream;

import lombok.Cleanup;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;

/**
 * FileReader 和FileWrite 实现文本文件复制
 *
 * @Description: FileReader 和FileWrite 实现文件复制
 * =======================
 * @Author: Jovi
 * =======================
 * @Date: Created in 2023-02-09
 * =======================
 * @Version: 1.1.2.0
 */
public class FileCopyDemo {

    public static void main(String[] args) throws Exception {

        File srcFile = new File("zzz.txt");
        File dstFile = new File("xxx.txt");

        @Cleanup FileReader fr = new FileReader(srcFile);
        @Cleanup FileWriter wr = new FileWriter(dstFile);

        char[] chars = new char[5];
        int len;
        while ((len = fr.read(chars)) != -1) {
            System.out.println(len);
            wr.write(chars, 0, len);
        }

    }
}
